package com.example.a33mvvm.video;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.example.base_mvvm.base.BaseViewModel;
import com.example.base_mvvm.entity.CommentEntity;
import com.example.base_mvvm.entity.FollowEntity;
import com.example.base_mvvm.entity.LikeEntity;
import com.example.base_mvvm.entity.VideoEntity;
import com.example.base_mvvm.net.Const;
import com.google.gson.Gson;

import java.util.HashMap;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class VideoViewModel extends BaseViewModel<VideoRepo> {
    public MutableLiveData<VideoEntity> video_success = new MutableLiveData<>();
    public MutableLiveData<String> video_failure = new MutableLiveData<>();
    public MutableLiveData<LikeEntity> like_success = new MutableLiveData<>();
    public MutableLiveData<String> like_failure = new MutableLiveData<>();
    public MutableLiveData<LikeEntity> disLike_success = new MutableLiveData<>();
    public MutableLiveData<String> disLike_failure = new MutableLiveData<>();
    public MutableLiveData<FollowEntity> follow_success = new MutableLiveData<>();
    public MutableLiveData<String> follow_failure = new MutableLiveData<>();
    public MutableLiveData<CommentEntity> putComment_success = new MutableLiveData<>();
    public MutableLiveData<String> putComment_failure = new MutableLiveData<>();
    public MutableLiveData<CommentEntity> getComment_success = new MutableLiveData<>();
    public MutableLiveData<String> getComment_failure = new MutableLiveData<>();
    public VideoViewModel(@NonNull Application application) {
        super(application);
    }
    public void video(int page,int size){
        repo.video(page,size,video_success,video_failure);
    }
    public void like(int id){
        repo.like(id,like_success,like_failure);
    }
    public void disLike(int id){
        repo.dislike(id,disLike_success,disLike_failure);
    }
    public void follow(String authname){
        HashMap<String, String> map = new HashMap<>();
        map.put(Const.AUTH_NAME,authname);
        String json = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse(Const.PARSE),json);
        repo.follow(body,follow_success,follow_failure);
    }
    public void getComment(int id){
        repo.getComment(id,getComment_success,getComment_failure);
    }
    public void putComment(String msg,int id){
        HashMap<String, Object> map = new HashMap<>();
        map.put(Const.MESSAGE,msg);
        map.put(Const.VIDEOID,id);
        String json = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse(Const.PARSE),json);
        repo.putComment(body,putComment_success,putComment_failure);
    }
    @Override
    protected VideoRepo createRepo() {
        return new VideoRepo();
    }
}
